package com.zjq.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.stereotype.Repository;

import com.zjq.pojo.Detail;
import com.zjq.pojo.Role;

@Repository("detailDao")
public class DetailDaoImpl extends BaseDaoImpl<Detail>{
	private Session session = null;
	private Query query = null;
	public void add(Detail d) {
		try {
			session = this.getHibernateTemplate().getSessionFactory().openSession();
			Transaction tr = session.beginTransaction();
			session.save(d);
			tr.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block

			e.printStackTrace();
		}
		if (session!=null&&session.isOpen()) {
			session.close();
		}
	}
	public List<?> findByNext(String name) {
		// TODO Auto-generated method stub

		List<?> list = null;
		String hql = "FROM Detail d WHERE d.roleByNextauditor.name=?&&d.state=0";
		try {
			session = this.getHibernateTemplate().getSessionFactory().openSession();
			list = session.createQuery(hql).setString(0, name).list();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block

			e.printStackTrace();
		}
		if (session!=null&&session.isOpen()) {
			session.close();
		}
		return list;
	}
}
